#include <STC89C5xRC.H>
#include "I2C.h"

#define AT24C02_Address 0xA0

/**
 * @brief 向AT24C02的字地址写入数据
 * @param WordAdress 字地址；Data 要写入的数据
 * @retval 无
 **/
void AT24C02_WriteByte(unsigned WordAddress,Data)
{	
	I2C_Strat();
	I2C_SendByte(AT24C02_Address);
	I2C_ReceiveAck();
	I2C_SendByte(WordAddress);
  I2C_ReceiveAck();
	I2C_SendByte(Data);
	I2C_ReceiveAck();
	I2C_Stop();
}

/**
 * @brief 向AT24C02的字地址读出数据
 * @param WordAddress 字地址
 * @retval 字地址中存储的数据
 **/
unsigned char AT24C02_ReadByte(unsigned char WordAddress)
{
	unsigned char Data;
	I2C_Strat();
	I2C_SendByte(AT24C02_Address);
	I2C_ReceiveAck();
	I2C_SendByte(WordAddress);
	I2C_ReceiveAck();
	I2C_Strat();
	I2C_SendByte(AT24C02_Address|0x01);
	I2C_ReceiveAck();
	Data=I2C_ReceiveByte();
	I2C_SendAck(1);
	I2C_Stop();
	return Data;
}